package com.hjm.project.merchantInfo.schedule.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.merchantInfo.schedule.domain.MerchantSchedule;
import com.hjm.project.merchantInfo.schedule.service.IMerchantScheduleService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 商户附Controller
 * 
 * @author LOVE
 * @date 2020-11-25
 */
@Controller
@RequestMapping("/merchantInfo/schedule")
public class MerchantScheduleController extends BaseController
{
    private String prefix = "merchantInfo/schedule";

    @Autowired
    private IMerchantScheduleService merchantScheduleService;

    @RequiresPermissions("merchantInfo:schedule:view")
    @GetMapping()
    public String schedule()
    {
        return prefix + "/schedule";
    }

    /**
     * 查询商户附列表
     */
    @RequiresPermissions("merchantInfo:schedule:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MerchantSchedule merchantSchedule)
    {
        startPage();
        List<MerchantSchedule> list = merchantScheduleService.selectMerchantScheduleList(merchantSchedule);
        return getDataTable(list);
    }

    /**
     * 导出商户附列表
     */
    @RequiresPermissions("merchantInfo:schedule:export")
    @Log(title = "商户附", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MerchantSchedule merchantSchedule)
    {
        List<MerchantSchedule> list = merchantScheduleService.selectMerchantScheduleList(merchantSchedule);
        ExcelUtil<MerchantSchedule> util = new ExcelUtil<MerchantSchedule>(MerchantSchedule.class);
        return util.exportExcel(list, "schedule");
    }

    /**
     * 新增商户附
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商户附
     */
    @RequiresPermissions("merchantInfo:schedule:add")
    @Log(title = "商户附", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MerchantSchedule merchantSchedule)
    {
        return toAjax(merchantScheduleService.insertMerchantSchedule(merchantSchedule));
    }

    /**
     * 修改商户附
     */
    @GetMapping("/edit/{merno}")
    public String edit(@PathVariable("merno") String merno, ModelMap mmap)
    {
        MerchantSchedule merchantSchedule = merchantScheduleService.selectMerchantScheduleById(merno);
        mmap.put("merchantSchedule", merchantSchedule);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户附
     */
    @RequiresPermissions("merchantInfo:schedule:edit")
    @Log(title = "商户附", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MerchantSchedule merchantSchedule)
    {
        return toAjax(merchantScheduleService.updateMerchantSchedule(merchantSchedule));
    }

    /**
     * 删除商户附
     */
    @RequiresPermissions("merchantInfo:schedule:remove")
    @Log(title = "商户附", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(merchantScheduleService.deleteMerchantScheduleByIds(ids));
    }
}
